export default {
	namespaced: true,
	state: () => ({
		address: JSON.parse(uni.getStorageSync('address') || '{}'),
		token: uni.getStorageSync('token') || '',
		userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		// 重定向的object对象 {openType, from }
		redirectInfo: JSON.parse(uni.getStorageSync('redirectInfo') || 'null'),
	}),
	mutations: {
		updateAddress(state, address) {
			state.address = address;
			this.commit('m_user/saveAddressToStorage')
		},
		updateUserInfo(state, userinfo){
			state.userinfo = userinfo
			this.commit('m_user/saveUserInfoToStorage')
			
		},
		updateToken(state, token){
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		updateRedirectInfo(state, redirectInfo) {
			state.redirectInfo = redirectInfo
			this.commit('m_user/saveRedirectInfoToStorage')
		},
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
			
		},
		saveAddressToStorage(state) {
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		saveTokenToStorage(state){
			uni.setStorageSync('token', JSON.stringify(state.token))
		},
		saveRedirectInfoToStorage(state){
			uni.setStorageSync('redirectInfo', JSON.stringify(state.redirectInfo))
		}
	},
	// 数据包装器
	getters: {
		addstr(state) {
			if (!state.address.provinceName) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}